package com.example.springbootjpa;

import com.example.springbootjpa.domain.User;
import com.example.springbootjpa.repositories.MyRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

/**
 * 由于该注解中具有功能:自动扫描与该类所在的包或者子包的的entity类,和repository接口(激活jpa repository)
 */
@SpringBootApplication
public class SpringBootJpaApplication {

    private static final Logger log = LoggerFactory.getLogger(SpringBootJpaApplication.class);

    public static void main(String[] args) {
        SpringApplication.run(SpringBootJpaApplication.class, args);
    }

    @Bean
    public CommandLineRunner demo(MyRepository repository){
        return (args)->{
            repository.save(new User(null,"张三","法师"));
            repository.save(new User(null,"李四","法师"));
            log.info("User found with findByusername");
            log.info("-------------------------------");
            log.info(repository.findByUsername("张三").toString());
            log.info(repository.findByUsername("李四").toString());
        };
    }
}
